package com.example.test.core.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    //声明队列
    @Bean
    public Queue queueOne() {
        return new Queue("hello.queue.one", true); // true表示持久化该队列
    }

    @Bean
    public Queue queueTwo() {
        return new Queue("hello.queue.two", true);
    }

    //声明交互器
    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange("TopicExchange");
    }

    //绑定
    @Bean
    public Binding bindingOne() {
        return BindingBuilder.bind(queueOne()).to(topicExchange()).with("key.one");
    }

    @Bean
    public Binding bindingTwo() {
        return BindingBuilder.bind(queueTwo()).to(topicExchange()).with("key.two");
    }

}
